﻿using System;
namespace Kis.Xroad.Eu {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="RRExtSideDataResponse", Namespace="http://kis.x-road.eu/", Target=typeof(RRExtSideDataResponse))]
    public class RRExtSideDataResponseSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected RRExtSideDataResponse clazz;
        
        public RRExtSideDataResponseSerializer(RRExtSideDataResponse clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.Isikud!=null) {
                Writer.WriteStartElement("Isikud");
                if (((clazz.Isikud == null) 
                            || (clazz.Isikud.Count < 1m))) {
                    throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "Isik");
                }
                for (int x = 0; ((clazz.Isikud != null) 
                            && (x < clazz.Isikud.Count)); x = (x + 1)) {
                    Writer.WriteStartElement("Isik");
                    if (clazz.Isikud[x]!=null) {
                        global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData(clazz.Isikud[x]);
                        if (ShouldWriteTypeAttribute(typeof(RRExtSideDataResponse.IsikudType), clazz.Isikud[x].GetType())) {
                            Writer.WriteTypeAttribute(metaIsikud.TypeQualifiedName.Namespace, metaIsikud.TypeQualifiedName.Name);
                        }
                        var isikudSerializer = metaIsikud.NewSerializer(clazz.Isikud[x]);
                        isikudSerializer.WriteXmlAttributes(Writer);
                        isikudSerializer.WriteXml(Writer);
                    }
                    else {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikud");
                    }
                    Writer.WriteEndElement();
                }
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="Isikud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>RRExtSideDataResponse>Isikud");
                }
                clazz.Isikud = new System.Collections.Generic.List<RRExtSideDataResponse.IsikudType>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("Isikud");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "Isik")); ) {
                        if (Reader.LocalName=="Isik") {
                            if (Reader.IsElementNil()) {
                                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>RRExtSideDataResponse>Isikud>Isik");
                            }
                            global::Xtee.Core.SerializationMetadata metaIsikud = this.GetMetaData<RRExtSideDataResponse.IsikudType>(Reader, ">>>RRExtSideDataResponse>Isikud>Isik", "http://kis.x-road.eu/");
                            RRExtSideDataResponse.IsikudType item = metaIsikud.NewEntity<RRExtSideDataResponse.IsikudType>();
                            clazz.Isikud.Add(item);
                            if ((Reader.IsEmptyElement == false)) {
                                var isikudSerializer = metaIsikud.NewSerializer(item);
                                isikudSerializer.ReadXmlAttributes(Reader);
                                Reader.ReadStartElement("Isik");
                                isikudSerializer.ReadXml(Reader);
                                Reader.ReadEndElement();
                            }
                            else {
                                Reader.Skip();
                            }
                        }
                        else {
                            throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>RRExtSideDataResponse>Isikud>Isik", Reader.LocalName);
                        }
                    }
                    if ((clazz.Isikud.Count < 1m)) {
                        throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "Isik");
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
        }
        
        [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>RRExtSideDataResponse>Isikud>Isik", Namespace="http://kis.x-road.eu/", Target=typeof(RRExtSideDataResponse.IsikudType))]
        public class IsikudTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
            
            protected RRExtSideDataResponse.IsikudType clazz;
            
            public IsikudTypeSerializer(RRExtSideDataResponse.IsikudType clazz) {
                this.clazz = clazz;
            }
            
            public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXmlAttributes(Writer);
            }
            
            public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                base.WriteXml(Writer);
                Writer.WriteStartElement("Isikukood");
                if (clazz.Isikukood!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Isikukood))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Isikukood");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Eesnimi");
                if (clazz.Eesnimi!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Eesnimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Eesnimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("Perenimi");
                if (clazz.Perenimi!=null) {
                    Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Perenimi))).ToString());
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Perenimi");
                }
                Writer.WriteEndElement();
                Writer.WriteStartElement("vead");
                if (clazz.Vead!=null) {
                    if (((clazz.Vead == null) 
                                || (clazz.Vead.Count < 1m))) {
                        throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "viga");
                    }
                    for (int x = 0; ((clazz.Vead != null) 
                                && (x < clazz.Vead.Count)); x = (x + 1)) {
                        Writer.WriteStartElement("viga");
                        if (clazz.Vead[x]!=null) {
                            global::Xtee.Core.SerializationMetadata metaVead = this.GetMetaData(clazz.Vead[x]);
                            if (ShouldWriteTypeAttribute(typeof(RRExtSideDataResponse.IsikudType.VeadType), clazz.Vead[x].GetType())) {
                                Writer.WriteTypeAttribute(metaVead.TypeQualifiedName.Namespace, metaVead.TypeQualifiedName.Name);
                            }
                            var veadSerializer = metaVead.NewSerializer(clazz.Vead[x]);
                            veadSerializer.WriteXmlAttributes(Writer);
                            veadSerializer.WriteXml(Writer);
                        }
                        else {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Vead");
                        }
                        Writer.WriteEndElement();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Vead");
                }
                Writer.WriteEndElement();
            }
            
            public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXmlAttributes(Reader);
            }
            
            public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                base.ReadXml(Reader);
                if (Reader.LocalName=="Isikukood") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RRExtSideDataResponse>Isikud>Isik>Isikukood");
                    }
                    clazz.Isikukood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Isikukood")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RRExtSideDataResponse>Isikud>Isik>Isikukood", Reader.LocalName);
                }
                if (Reader.LocalName=="Eesnimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RRExtSideDataResponse>Isikud>Isik>Eesnimi");
                    }
                    clazz.Eesnimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Eesnimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RRExtSideDataResponse>Isikud>Isik>Eesnimi", Reader.LocalName);
                }
                if (Reader.LocalName=="Perenimi") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RRExtSideDataResponse>Isikud>Isik>Perenimi");
                    }
                    clazz.Perenimi = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("Perenimi")).Value;
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RRExtSideDataResponse>Isikud>Isik>Perenimi", Reader.LocalName);
                }
                if (Reader.LocalName=="vead") {
                    if (Reader.IsElementNil()) {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>RRExtSideDataResponse>Isikud>Isik>vead");
                    }
                    clazz.Vead = new System.Collections.Generic.List<RRExtSideDataResponse.IsikudType.VeadType>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("vead");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "viga")); ) {
                            if (Reader.LocalName=="viga") {
                                if (Reader.IsElementNil()) {
                                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga");
                                }
                                global::Xtee.Core.SerializationMetadata metaVead = this.GetMetaData<RRExtSideDataResponse.IsikudType.VeadType>(Reader, ">>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga", "http://kis.x-road.eu/");
                                RRExtSideDataResponse.IsikudType.VeadType item = metaVead.NewEntity<RRExtSideDataResponse.IsikudType.VeadType>();
                                clazz.Vead.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    var veadSerializer = metaVead.NewSerializer(item);
                                    veadSerializer.ReadXmlAttributes(Reader);
                                    Reader.ReadStartElement("viga");
                                    veadSerializer.ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga", Reader.LocalName);
                            }
                        }
                        if ((clazz.Vead.Count < 1m)) {
                            throw new global::Xtee.Core.Exceptions.MinOccurrenceException(1m, "viga");
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>RRExtSideDataResponse>Isikud>Isik>vead", Reader.LocalName);
                }
            }
            
            [global::Xtee.Core.Attributes.XmlTypeAttribute(Name=">>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga", Namespace="http://kis.x-road.eu/", Target=typeof(RRExtSideDataResponse.IsikudType.VeadType))]
            public class VeadTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
                
                protected RRExtSideDataResponse.IsikudType.VeadType clazz;
                
                public VeadTypeSerializer(RRExtSideDataResponse.IsikudType.VeadType clazz) {
                    this.clazz = clazz;
                }
                
                public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
                    base.WriteXmlAttributes(Writer);
                }
                
                public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
                    base.WriteXml(Writer);
                    Writer.WriteStartElement("kood");
                    if (clazz.Kood!=null) {
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Kood))).ToString());
                    }
                    else {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Kood");
                    }
                    Writer.WriteEndElement();
                    Writer.WriteStartElement("tekst");
                    if (clazz.Tekst!=null) {
                        Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Tekst))).ToString());
                    }
                    else {
                        throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Tekst");
                    }
                    Writer.WriteEndElement();
                }
                
                public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
                    base.ReadXmlAttributes(Reader);
                }
                
                public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
                    base.ReadXml(Reader);
                    if (Reader.LocalName=="kood") {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga>kood");
                        }
                        clazz.Kood = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("kood")).Value;
                    }
                    else {
                        throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga>kood", Reader.LocalName);
                    }
                    if (Reader.LocalName=="tekst") {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga>tekst");
                        }
                        clazz.Tekst = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("tekst")).Value;
                    }
                    else {
                        throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>>>>RRExtSideDataResponse>Isikud>Isik>vead>viga>tekst", Reader.LocalName);
                    }
                }
            }
        }
    }
}
